<template>
	<zui-box>
		<!-- 头部导航 -->
		<zui-navbar :title="`${tit}记录`"></zui-navbar>
		<u-gap height="30rpx"></u-gap>
	
		<mescroll-body :height="mescroll_height +'px'" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
		:up="upOption">
		
		
		<zui-flat bgColor="#EEAE4F">
			<zui-col height="228rpx">
				<view class="col_text">当前{{ tit }}</view>
				<view class="col_price" v-if="type == 1">{{ info.balance }}</view>
				<view class="col_price" v-if="type == 2">{{ info.gold }}</view>
				<view class="col_price" v-if="type == 3">{{ info.vouchers }}</view>
				<view class="col_price" v-if="type == 4">{{ info.point_num }}</view>
				<view class="right_btn">
					<u-button type="primary" v-if="type == 1" :icon="require('@/static/img/qianbi.png')" @click="xz_go('recharge')" text="充值"></u-button>
					<u-button type="primary" v-if="type == 2" :icon="require('@/static/img/qianbi.png')" @click="xz_go('convert')" text="兑换"></u-button>
					
				</view>
				<view class="right_text" v-if="type == 3">
					<view>
						今日可以买卖{{exchange_num}}克
					</view>
					<view>
						今日已经买卖{{have_consume_num}}克 
					</view>
				</view>
			</zui-col>
		</zui-flat>
		<u-gap height="30rpx"></u-gap>
		<view class="tabs_box">
			<u-tabs
				lineColor="#AA334F"
				:current="record_type"
				:activeStyle="{ color: '#AA334F' }"
				:inactiveStyle="{ color: '#9D97A7' }"
				:list="tab_list"
				@click="tabchange"
			></u-tabs>
		</view>
		<u-gap height="30rpx"></u-gap>

		<view class="list">
			
			<view class="item" v-for="val in list" :key="val.id">
				<zui-flat bgColor="#fff">
					<zui-col height="154rpx">
						<view class="col_name">{{ val.remarks }}</view>
						<view class="col_time">{{ val.create_time }}</view>
						<view class="col_right" :style="Number(val.aft_num) > Number(val.bfr_num) ? '' : 'color:#20e713;'">{{ val.num }}</view>
					</zui-col>
				</zui-flat>
				<u-gap height="30rpx"></u-gap>
			</view>
			
				
<!-- 			<view class="" v-if="list.length === 0"><u-empty mode="coupon" text=" "></u-empty></view>
			<u-loadmore status="status" :icon-type="iconType" :load-text="loadText" /> -->
		</view>
		</mescroll-body>
	
			
			
	</zui-box>
</template>

<script>
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	export default {
		mixins: [MescrollMixin,uni.$u.mpMixin, uni.$u.mixin],
	data() {
		return {
			tit: '',
			ajaxurl: '',
			info: {},
			page: 1,
			type: 1,
			record_type: 0,
			exchange_num: 0,
			have_consume_num: 0,
			tab_list: [
				{
					name: '全部'
				},
				{
					name: '收入'
				},
				{
					name: '支出'
				}
			],
			list: [],
			// 下拉刷新的配置(可选, 绝大部分情况无需配置)
			downOption: {
				auto: false //是否在初始化后,自动执行downCallback; 默认true
			},
			upOption: {
				auto: false // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
			},
			mescroll_height:'',
		};
	},
	created() {
		let that = this;
		   uni.getSystemInfo({ 
			success(res) {
			console.log('一',res.windowHeight); //可使用窗口高度
			that.mescroll_height = res.windowHeight - that.$u.getPx(uni.$u.props.navbar.height) - that.$u.sys().statusBarHeight -80
			
			console.log('二',that.mescroll_height)
			}
		})
	},
	onLoad(data) {
		this.type = data.type;
		if (data.type == 1) {
			this.tit = '余额';
			this.ajaxurl = '/app/user/getBalanceList';
		} else if (data.type == 2) {
			this.tit = '金元';
			this.ajaxurl = '/app/user/getGoldList';
		} else if (data.type == 3) {
			this.tit = '购物券';
			this.ajaxurl = '/app/user/getVouchersList';
		} else if (data.type == 4) {
			this.tit = '金豆';
			this.ajaxurl = '/app/user/getPointsList';
		}
	},
	
	onShow() {
	
	},
	onShow() {
		this.get_info();
		// this.getdata();
		this.$nextTick(()=>{
			this.mescroll.resetUpScroll();
		})
	},
	methods: {
		get_info() {
			uni.$u.http
				.get('/app/user/getUserInfo', {
					params: {},
					custom: {
						auth: true,
						toast: true,
						catch: true
					}
				})
				.then(res => {
					this.info = res;
				})
				.catch(err => {});
		},
		//下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
		downCallback() {
			setTimeout(() => {
				this.mescroll.resetUpScroll();
			}, 1000);
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		 upCallback(page) {
			 
			uni.$u.http
				.get(this.ajaxurl, {
					params: {
						page: page.num,
						record_type: this.record_type
					},
					custom: {
						auth: true,
						toast: false,
						catch: false,
					},
				})
				.then(res => {
					console.log('返回的数据', res);
					this.exchange_num = res.exchange_num;
					this.have_consume_num = res.have_consume_num;
					this.mescroll.endSuccess(res.list.length);
					//设置列表数据
					if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.list); //追加新数据
		
				})
				.catch(res => {
					this.mescroll.endErr();
				});
		},
		// getdata() {
		// 	this.status = 'loading';
		// 	uni.$u.http
		// 		.get(this.ajaxurl, {
		// 			params: {
		// 				page: this.page,
		// 				record_type: this.record_type
		// 			},
		// 			custom: {
		// 				auth: true,
		// 				toast: true,
		// 				catch: true
		// 			}
		// 		})
		// 		.then(res => {
		// 			if (res.list.length == 0) {
		// 				this.status = 'nomore';
		// 			} else {
		// 				this.status = 'loadmore';
		// 				this.list = [...this.list, ...res.list];
		// 				if (res.page > res.total_page) {
		// 					this.status = 'nomore';
		// 				}
		// 				this.page++;
		// 			}
		// 		})
		// 		.catch(err => {});
		// },
		tabchange(data) {
			this.record_type = data.index;
			
			this.mescroll.resetUpScroll();
		}
	},
	// onReachBottom() {
	// 	if (this.status == 'loadmore') {
	// 		this.getdata();
	// 	}
	// }
};
</script>

<style lang="scss" scoped>
	
	/* //空数据 */
		/deep/.mescroll-empty {
			box-sizing: border-box;
			width: 100%;
			padding: 200rpx 50rpx;
			text-align: center;
		}
		
		
.list {
	// padding-bottom: 100rpx;
}
.col_text {
	font-size: 30rpx;
	color: #fff;
}
.col_price {
	font-size: 40rpx;
	color: #fff;
}

.col_name {
	font-size: 28rpx;
	color: #272727;
}
.col_time {
	font-size: 24rpx;
	color: #BEBDBD;
}
.col_right {
	color: #e73333;
	font-size: 32rpx;
	position: absolute;
	right: 30rpx;
}
.right_btn {
	position: absolute;
	width: 146rpx;
	height: 68rpx;
	right: 0;
	/deep/.u-button {
		padding: 0 30rpx;
		border: 0;
		background: #f8e0bb !important;
		box-shadow: -4rpx 0px 8rpx 2rpx rgba(139, 92, 21, 0.3);
		border-radius: 36rpx 0 0 36rpx;
		color: #eeae4f;
	}
}
.right_text {
	position: absolute;
	// width: 146rpx;
	// height: 68rpx;
	    text-align: right;
	color: #fff;
	font-size: 30rpx;
	
	right: 30rpx;
	line-height: 2;
}

/deep/.tabs_box {
	display: flex;
	justify-content: center;
}
/deep/.u-tabs__wrapper__nav__item {
	padding: 0 60rpx;
}
</style>
